package com.xinguan.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


/**
 * 统一返回参数
 * @param <T>
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private Integer code;
    private String message;
    private T data;
    public Result(Integer code, String msg) {
        this.code = code;
        this.message= msg;
    }
    public static<T>  Result<T> success(){
        return new Result<>(200,"success",null);
    }

    public static<T>  Result<T> success(T data){
        return new Result<>(201,"success",data);
    }
    public static<T>  Result<T> success(String message,T data){
        return new Result<>(200,message,data);
    }


    public static<T>  Result<T> success(T data, String message){
        return new Result<>(20000,message,data);
    }

    public static<T>  Result<T> success(String message){
        return new Result<>(200,message,null);
    }
    public static<T>  Result<T> success(Integer id,String message){
        return new Result<>(id,message,null);
    }

    public static<T>  Result<T> fail(){
        return new Result<>(20001,"fail",null);
    }

    public static<T>  Result<T> fail(Integer code){
        return new Result<>(code,"fail",null);
    }

    public static<T>  Result<T> fail(Integer code, String message){
        return new Result<>(code,message,null);
    }

    public static<T>  Result<T> fail( String message){
        return new Result<>(20001,message,null);
    }

}